﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CMS_Admin_PartControl : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DoAdd.Visible = false;
        DoSave.Visible = false;

        try
        {
            if (!IsPostBack)
            {
                Bind();
               
            }
        }
        catch
        {

        }
    }

    private void Bind()
    {
        Usas.Common.Cms.Role.RedType rt = new Usas.Common.Cms.Role.RedType();
        switch (Request["tid"].ToString())
        {
            case "a":
                rt = Usas.Common.Cms.Role.RedType.Article;
                //sm = CMS_Control_PartControl.ShowMode.Article;
                break;
            case "b":
                rt = Usas.Common.Cms.Role.RedType.Border;
                //sm = CMS_Control_PartControl.ShowMode.Border;
                break;
        }

        if (Request["action"].ToString() == "edit")
        {
            PartControl1.UserIntiPart(rt, Convert.ToInt32(Request["id"]), true);
            //PartControl1.UserIntiPart(sm, Convert.ToInt32(Request["id"]), true, true, true);
            DoSave.Visible = true;
            DoAdd.Visible = false;
            Save.Attributes.Add("onclick", "return confirm('确认修改？')");
        }
        else
        {
            PartControl1.UserIntiPart(rt, Convert.ToInt32(Request["id"]), false);

          
            DoAdd.Visible = true;
            Add.Attributes.Add("onclick", "return confirm('确认添加？')");
        }
    }
    protected void Save_Click(object sender, EventArgs e)
    {
        string ValStr = PartControl1.Val();
        if (ValStr.Length <= 0)
        {

            if (PartControl1.SaveAction(false))
            {
                ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('修改成功！');parent.location.reload()", true);
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('" + ValStr + "')", true);
        }



    }

    protected void Add_Click(object sender, EventArgs e)
    {
        string ValStr = PartControl1.Val();
        if (ValStr.Length <= 0)
        {
            Usas.Common.Cms.Role.RedType rt = new Usas.Common.Cms.Role.RedType();

            switch (Request["tid"].ToString())
            {
                case "a":
                    rt = Usas.Common.Cms.Role.RedType.Article;
                    break;
                case "b":
                    rt = Usas.Common.Cms.Role.RedType.Border;
                    break;
            }

            if (PartControl1.AddAction(rt, Convert.ToInt32(Request["id"])))
            {
                ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('添加成功！');parent.location.reload()", true);
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('" + ValStr + "')", true);
        }
    }
}
